function junmToIosIndex() {
    var u = navigator.userAgent;
    if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {
        AndroidWebView.gotoback();
    } else if (u.indexOf('iPhone') > -1) {
        window.webkit.messageHandlers.iOS_goback.postMessage('iOS_goback');
    } else {
        getOther();
    }
}

var transactionObj = {
    orderid: "",
    form:"",
    sUserId: "",//订单 用户did
    sCorpId: "",//订单 corpid
    lId : "",
    nApproveStatus:"",
    bShoppingGuide:false,
    init: function () {
        $(".bottomnav").hide();
        publicObj.getIosAndData();
        this.orderid = publicObj.getUrlData("oriderid");
        this.form = publicObj.getUrlData("form");
        this.getTransantionDetail();
    },
    getTransantionDetail: function () {
        var reqType = "POST";
        var isAsync = true;
        var dataType = "json";
        var reqUrl = ruquireObj.urlPrefix + 'OrderService/getdeptmallorderbyid';
        var reqBody = {};
        reqBody.sDealCount = this.orderid;
        publicObj.myAjax(this, this.getTDsug, reqUrl, reqBody, reqType, isAsync, dataType);
    },
    getTDsug: function (res, obj) {
        if (res.return.nCode == 0) {
            var resObj = res.response;
            //console.log(resObj);
            //商品列表
            var dataList = resObj.cdoOrderData;
            obj.bShoppingGuide = resObj.bShoppingGuide;
            console.log(resObj);
            var str = '';
            //商品信息列表
            var goodsStr = '';
            var returnGoodsArr = [];
            for (var j = 0; j < dataList.posSaledtl.length; j++) {
                goodsStr += '<div class="center kind1"><div class="goodsname"><div class="goodsnametxt">' + dataList.posSaledtl[j].sGoodsName + '</div><div class="barcode">' + dataList.posSaledtl[j].sBarcode + '</div></div><div class="pric">￥' + publicObj.reduceNum(dataList.posSaledtl[j].nPluAmount,dataList.posSaledtl[j].nPluDis)  + '</div><div class="num">' + dataList.posSaledtl[j].nQty + '</div></div>'
                if(dataList.posSaledtl[j].nReturnCount > 0){
                    returnGoodsArr.push(dataList.posSaledtl[j]);
                }
            }
            str += '<div class="datalistbox"><div class="top">订单编号：' + dataList.sDealCount + '<text class="approvalstatus"></text></div><div class="centerbox"><div class="normalgoods">' + goodsStr + '</div><div class="totalbox totalbox2"></div></div></div>';
            $('.datalistwall').html(str);
            //退款商品列表
           console.log(returnGoodsArr);
           if(returnGoodsArr.length == 0){
               $(".returnwall").hide();
           }else {
               var returnGoodsStr = '';
               for (var c = 0; c < returnGoodsArr.length; c++) {
                   returnGoodsStr += '<div class="returnbox"><div class="centerbox"><div class="center kind1"><div class="goodsname"><div class="goodsnametxt">' + returnGoodsArr[c].sGoodsName + '</div><div class="barcode">' + returnGoodsArr[c].sBarcode + '</div></div><div class="pric">退款￥' + returnGoodsArr[c].nReturnVal   + '</div><div class="num">' + returnGoodsArr[c].nReturnCount + '</div></div></div></div>'
               }
               $(".returnwall").html(returnGoodsStr);
           }
            //支付信息,优惠信息

           console.log(resObj)
            var disArr = [];
            for (var a = 0; a < dataList.posPayMent.length; a++) {
                if (dataList.posPayMent[a].nPayTypeId == 1 || dataList.posPayMent[a].nPayTypeId == 2 || dataList.posPayMent[a].nPayTypeId == 5) {
                    $(".payinfor1").text(dataList.posPayMent[a].dCreateTime);
                    $(".payinfor2").text(dataList.posPayMent[a].sPayName);
                    $(".payinfor5").text(resObj.cdoOrderData.sDealCount);
                    $(".payinfor6").text(resObj.cdoOrderData.nTransId);
                    if(resObj.nPoint == '-1'){
                        $(".hyjf").hide();
                    }else {
                        $(".payinfor7").text(resObj.nPoint);
                    }

                    if (dataList.approve) {
                        $(".thcz").show();
                        $(".payinfor4").text(dataList.approve.sInitUserName);
                    } else {
                        $(".thcz").hide();
                        $(".payinfor4").text('无');
                    }
                }
                if(dataList.posPayMent[a].nPayTypeId != 1 &&dataList.posPayMent[a].nPayTypeId != 2 && dataList.posPayMent[a].nPayTypeId != 5){
                    var disObj = dataList.posPayMent[a];
                    disArr.push(disObj);
                }
            }

            $(".total > .right").html('￥'+resObj.cdoOrderData.nRealPayVal);
            console.log(dataList.posPayMent)
            console.log(disArr)
            //优惠信息展示
            var disStr = '';
            for (var b = 0; b < disArr.length; b++) {
                disStr += '<div class="offer">\n' +
                    '            <div class="left">'+disArr[b].sPayName+'</div>\n' +
                    '            <div class="right">-￥'+disArr[b].nPayVal+'</div>\n' +
                    '        </div>'
            }
            $(".offerlist").html(disStr);
            // 附件图片
            var posadExt = dataList.posHeadExt;
            var imgStr = "";
            if (posadExt) {
                if( posadExt.sImgUrl == ""){
                    $(".venture").hide();
                }else {
                    var imgArry = posadExt.sImgUrl.split(",");
                    for (var k = 0; k < imgArry.length; k++) {
                        imgStr += ' <div class="imgwall" imgsrc="'+imgArry[k]+'"><img src="' + imgArry[k] + '"></div>';
                    }
                    $(".imgbox").html(imgStr);

                }
            } else {
                $(".venture").hide();
            }
            //附件留言
            if(posadExt != undefined){
                if(posadExt.sRemark == ""){
                    $(".remarksox").hide();
                }else {
                    $(".remarksox").show();
                    $(".remarksox >.remarkstxt").html(posadExt.sRemark);
                }
            }else {
                $(".remarksox").hide();
            }



            // 上级审批

            if (dataList.approve) {
                console.log(dataList.approve)
                var approvestate;
                obj.nApproveStatus = dataList.approve.nApproveStatus;
                if(dataList.approve.nApproveStatus == 0){
                    approvestate = '审批中';
                }else  if(dataList.approve.nApproveStatus == 1){
                    approvestate = '已同意';
                }else  if(dataList.approve.nApproveStatus == 99){
                    approvestate = '已撤销申请';
                }else  if(dataList.approve.nApproveStatus == 98){
                    approvestate = '退款失败';
                }else {
                    approvestate = '已拒绝';
                }
                $(".approvalstatus").html(approvestate);
                obj.lId = dataList.approve.lId;
                if(dataList.approve.nApproveStatus == 99){
                    $(".astatus").html(approvestate);
                    $(".hearimg").hide();
                }else{
                    $(".astatus").html(dataList.approve.sApproveUserName +'&nbsp&nbsp'+approvestate);
                    $(".hearimg").html('<img src="'+dataList.approve.userHeadPicPath+'">');
                    $(".approvtime").html(dataList.approve.sApproveTime);
                }
                $(".approvalbox").show();
            } else {
                $(".approvalbox").hide();
                obj.nApproveStatus = null;
            }
            //底部操作
            if(obj.form == "operadata"){
                $(".bottomnav").hide();
            }else {
                $(".bottomnav").show();
            }
            obj.sUserId = dataList.sUserId;
            obj.sCorpId = dataList.sCorpId;
            obj.bingEvent(obj);
        } else {

        }
    },
    //绑定事件
    bingEvent:function (obj) {
        //判断是否导购
        if(obj.bShoppingGuide){
            $(".daogo").show();
            $(".other").hide();
        }else{
            $(".daogo").hide();
            $(".other").show();
        }

        //按钮全部隐藏
        $(".orefund").hide();
        $(".refundDetail").hide();
        $(".returnApply").hide();
        $(".reloadorefund").hide();

        //根据状态 显示操作按钮
        if(obj.nApproveStatus == 0){
            $(".returnApply").show();
            $(".Agree").show();
            $(".refuse").show();
        }

        if(obj.nApproveStatus == 1){
            $(".refundDetail").show();
            $(".orefund").show();
        }

        if(obj.nApproveStatus == 99){
            $(".reloadorefund").show();
        }
        if(obj.nApproveStatus == 98){
            $(".reloadorefund").show();
        }
        if(obj.nApproveStatus == 2){
            $(".reloadorefund").show();
        }

        if(obj.nApproveStatus == null){
            $(".orefund").show();
        }
        //查看图片
        $(".imgwall").each(function () {
            $(this).unbind('click').bind('click', function (e) {
                var imgsrc = $(this).attr("imgsrc");
                console.log(imgsrc)
                location.href = "./img.html?imgsrc="+imgsrc;
            });
        });

        //重新申请退款
        $(".reloadorefund").each(function () {
            $(this).bind('click', function (e) {
                location.href = "./operationrefund.html?oriderid="+obj.orderid;
            });
        });

        //申请退款
        $(".orefund").each(function () {
            $(this).bind('click', function (e) {
                location.href = "./operationrefund.html?oriderid="+obj.orderid;
            });
        });

        //退款详情
        $(".refundDetail").bind("click",function () {
            var url = "./retunddetails.html?oriderid="+obj.orderid+"&sUserId="+obj.sUserId+"&storeId="+sessionStorage.getItem("sStoreId");
            location.href = url;
        });

        //撤销退款申请
        $(".returnApply").bind("click",function () {
            publicObj.showLoad();
            var reqType = "POST";
            var isAsync = true;
            var dataType = "json";
            var reqUrl = ruquireObj.urlPrefix+'ApproveService/cancleapproves';
            var reqBody={};
            reqBody.lId = obj.lId;
            publicObj.myAjax(obj,obj.returnApplyRe,reqUrl,reqBody,reqType,isAsync,dataType);
        });
        //同意退款
        $(".Agree").bind("click",function () {
            obj.handleApprove(obj,"1","允许通过");
        });
        //拒绝退款
        $(".refuse").bind("click",function () {
            obj.handleApprove(obj,"2","拒绝");
        });

    },

    handleApprove:function (obj,nApproveStatus,sApproveResult) {
        publicObj.showLoad();
        var reqType = "POST";
        var isAsync = true;
        var dataType = "json";
        var reqUrl = ruquireObj.urlPrefix+'ApproveService/handleapproves';
        var reqBody={};
        reqBody.lId = obj.lId;
        reqBody.nApproveStatus = nApproveStatus;
        reqBody.sApproveResult = sApproveResult;
        publicObj.myAjax(obj,obj.handleApproveRe,reqUrl,reqBody,reqType,isAsync,dataType);
    },

    handleApproveRe:function (res,obj) {
        if (res.return.nCode == 0) {
            publicObj.myalert("操作成功");
            setTimeout("junmToIosIndex();",2000);
        }else{
            publicObj.myalert(res.return.strText);
        }
        publicObj.hideLoad();
    },

    returnApplyRe:function (res,obj) {
        if (res.return.nCode == 0) {
            publicObj.myalert("撤回成功");

            setTimeout("junmToIosIndex();",2000);
        }else{
            publicObj.myalert(res.return.strText);
        }
        publicObj.hideLoad();
    }

};
transactionObj.init();